package com.huisou.domain;

import java.io.Serializable;
import java.util.Set;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Transient;

/**
 * 企业行业分类 --------------------- 2011-6-24
 */
@Entity
@Table(name = "tbl_enterprise_profession")
public class Profession implements Serializable {
	
	private static final long	serialVersionUID	= -1919674139448515137L;
	@Id
	@Column(name = "id")
	@GeneratedValue
	private Integer				id;
	@Column(name = "name")
	private String				name;
	@Column(name = "code")
	private String				code;
	@Column(name = "parent_id")
	private Integer				parentId;										// 父类别Id
	@Column(name = "is_parent")
	private Short				isParent;										// 是否为父类别
																				
	@Column(name = "sort")
	private Short				orderNo;										// 顺序号
	@Transient
	private int					dataCount;
	
	/**
	 * 父类别（定义列名）
	 * 
	 * @JoinColumn与@Column相区别的是：@JoinColumn注释的是保存表与表之间关系的字段， 它要标注在实体属性上。而 @Column标注的是表中不包含表关系的字段。
	 */
	@ManyToOne(optional = true, fetch = FetchType.LAZY)
	// 多对一的关联
	@JoinColumn(name = "parent_id", insertable = false, updatable = false)
	// 这是自关联的pid列名设置
	private Category			parent;
	/**
	 * 子类别列表,一对多，mappedBy="parent"表示由parent主导（即在parent端有值）
	 */
	@OneToMany(mappedBy = "parent", fetch = FetchType.LAZY)
	private Set<Category>		subCategories;
	
	public Profession() {
	}
	
	public Profession(Integer id, String name) {
		this.id = id;
		setName(name);
	}
	
	public String getName() {
		return name;
	}
	
	public void setName(String name) {
		this.name = name;
	}
	
	public String getCode() {
		return code;
	}
	
	public void setCode(String code) {
		this.code = code;
	}
	
	public Integer getParentId() {
		return parentId;
	}
	
	public void setParentId(Integer parentId) {
		this.parentId = parentId;
	}
	
	public Short getOrderNo() {
		return orderNo;
	}
	
	public void setOrderNo(Short orderNo) {
		this.orderNo = orderNo;
	}
	
	public int getDataCount() {
		return dataCount;
	}
	
	public void setDataCount(int dataCount) {
		this.dataCount = dataCount;
	}
	
	public Integer getId() {
		return id;
	}
	
	public void setId(Integer id) {
		this.id = id;
	}
	
	public Category getParent() {
		return parent;
	}
	
	public void setParent(Category parent) {
		this.parent = parent;
	}
	
	public Set<Category> getSubCategories() {
		return subCategories;
	}
	
	public void setSubCategories(Set<Category> subCategories) {
		this.subCategories = subCategories;
	}
	
	public Short getIsParent() {
		return isParent;
	}
	
	public void setIsParent(Short isParent) {
		this.isParent = isParent;
	}
}
